﻿Public Class DposCli

    Public Shared Function SeleccionarTodo() As List(Of Eposcli)
        Dim posclientes As List(Of Eposcli) = Nothing

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings("BDEvolta").ConnectionString)
            Using cmd As New SqlCommand("usp_posCli_sel", cn)
                cmd.CommandType = CommandType.StoredProcedure
                Try
                    cn.Open()
                    Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.CloseConnection)
                        If dr.HasRows Then
                            posclientes = New List(Of Eposcli)
                            Dim cliente As Eposcli = Nothing
                            Do While dr.Read
                                cliente = New Eposcli( _
                                    dr.GetInt32(dr.GetOrdinal("idPosCli")), _
                                    dr.GetString(dr.GetOrdinal("nombre")), _
                                    dr.GetString(dr.GetOrdinal("apePaterno")), _
                                    dr.GetString(dr.GetOrdinal("apeMaterno")), _
                                    dr.GetInt32(dr.GetOrdinal("idTpoDcmto")), _
                                    dr.GetString(dr.GetOrdinal("descTpoDcmto")), _
                                    dr.GetString(dr.GetOrdinal("nroDcmto")), _
                                    dr.GetString(dr.GetOrdinal("email")), _
                                    dr.GetInt32(dr.GetOrdinal("edad")), _
                                    dr.GetString(dr.GetOrdinal("telfijo")), _
                                    dr.GetString(dr.GetOrdinal("telmovil")), _
                                    dr.GetString(dr.GetOrdinal("telLab")), _
                                    dr.GetString(dr.GetOrdinal("ubigeo")), _
                                    dr.GetString(dr.GetOrdinal("centroLaboral")), _
                                    dr.GetString(dr.GetOrdinal("comentario")))
                                posclientes.Add(cliente)
                            Loop
                            dr.Close()
                        End If
                    End Using
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return posclientes
    End Function
    Public Shared Function Añadir(ByVal nombre As String, ByVal apePaterno As String, ByVal apeMaterno As String, ByVal edad As Int32, _
                                  ByVal email As String, ByVal telfijo As String, ByVal telmovil As String, ByVal telLab As String, _
                                  ByVal ubigeo As String, ByVal centroLaboral As String, ByVal comentario As String) As Boolean
        Dim resultado As Boolean = False

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings("BDEvolta").ConnectionString)
            Using cmd As New SqlCommand("usp_posCli_add", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@nombre", SqlDbType.VarChar, 55).Value = nombre
                cmd.Parameters.Add("@apePaterno", SqlDbType.VarChar, 55).Value = apePaterno
                cmd.Parameters.Add("@apeMaterno", SqlDbType.VarChar, 55).Value = apeMaterno
                cmd.Parameters.Add("@edad", SqlDbType.Int, 11).Value = edad
                cmd.Parameters.Add("@email", SqlDbType.VarChar, 40).Value = email
                cmd.Parameters.Add("@telfijo", SqlDbType.VarChar, 11).Value = telfijo
                cmd.Parameters.Add("@telmovil", SqlDbType.VarChar, 9).Value = telmovil
                cmd.Parameters.Add("@telLab", SqlDbType.SmallInt, 11).Value = telLab
                cmd.Parameters.Add("@ubigeo", SqlDbType.Char, 6).Value = ubigeo
                cmd.Parameters.Add("@centroLaboral", SqlDbType.VarChar, 55).Value = centroLaboral
                cmd.Parameters.Add("@comentario", SqlDbType.VarChar, 55).Value = comentario
                Try
                    cn.Open()
                    cmd.ExecuteNonQuery()
                    resultado = True
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return resultado
    End Function
    Public Shared Function Editar(ByVal idPosCli As Int32, ByVal nombre As String, ByVal apePaterno As String, ByVal apeMaterno As String, ByVal edad As Int32, _
                                  ByVal email As String, ByVal telfijo As String, ByVal telmovil As String, ByVal telLab As String, _
                                  ByVal ubigeo As String, ByVal centroLaboral As String, ByVal comentario As String) As Boolean
        Dim resultado As Boolean = False

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings("BDEvolta").ConnectionString)
            Using cmd As New SqlCommand("usp_posCli_edit", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idPosCli", SqlDbType.Int).Value = idPosCli
                cmd.Parameters.Add("@nombre", SqlDbType.VarChar, 55).Value = nombre
                cmd.Parameters.Add("@apePaterno", SqlDbType.VarChar, 55).Value = apePaterno
                cmd.Parameters.Add("@apeMaterno", SqlDbType.VarChar, 55).Value = apeMaterno
                cmd.Parameters.Add("@edad", SqlDbType.Int, 11).Value = edad
                cmd.Parameters.Add("@email", SqlDbType.VarChar, 40).Value = email
                cmd.Parameters.Add("@telfijo", SqlDbType.VarChar, 11).Value = telfijo
                cmd.Parameters.Add("@telmovil", SqlDbType.VarChar, 9).Value = telmovil
                cmd.Parameters.Add("@telLab", SqlDbType.VarChar, 11).Value = telLab
                cmd.Parameters.Add("@ubigeo", SqlDbType.Char, 6).Value = ubigeo
                cmd.Parameters.Add("@centroLaboral", SqlDbType.VarChar, 55).Value = centroLaboral
                cmd.Parameters.Add("@comentario", SqlDbType.VarChar, 55).Value = comentario
                Try
                    cn.Open()
                    cmd.ExecuteNonQuery()
                    resultado = True
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return resultado
    End Function

    Public Shared Function Eliminar(ByVal idPosCli As Int32) As Boolean
        Dim resultado As Boolean = False

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings("BDEvolta").ConnectionString)
            Using cmd As New SqlCommand("usp_posCli_del", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idPosCli", SqlDbType.Int).Value = idPosCli
                Try
                    cn.Open()
                    cmd.ExecuteNonQuery()
                    resultado = True
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return resultado
    End Function


End Class
